package com.hzj.recipe.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzj.recipe.entity.Collect;
import com.hzj.recipe.entity.Collect;
import com.hzj.recipe.mapper.CollectMapper;
import com.hzj.recipe.service.CollectService;
import com.hzj.recipe.mapper.CollectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
* @author 蜗牛菌
* @description 针对表【collect(收藏表)】的数据库操作Service实现
* @createDate 2024-01-04 10:49:47
*/
@Service
public class CollectServiceImpl extends ServiceImpl<CollectMapper, Collect>
    implements CollectService{

    @Autowired
    private CollectMapper collectMapper;

    @Override
    public Object listAll(Integer index, Integer size, Collect collect) {
        //默认第一页开始，每页5条
        if(index == null ||index==0){
            index=1;
        }
        if(size==null||size==0){
            size=5;
        }
        Page<Collect> pageInfo = new Page(index, size);
        LambdaQueryWrapper<Collect> lambdaQueryWrapper = new LambdaQueryWrapper();
        if (collect.getCollectId() != null && collect.getCollectId() != 0 && !Objects.equals(collect.getCollectId(), "")) {
            lambdaQueryWrapper.eq(Collect::getCollectId, collect.getCollectId());
        }
        if (collect.getUserId() != null && collect.getUserId() != 0 && !Objects.equals(collect.getUserId(), "")) {
            lambdaQueryWrapper.eq(Collect::getUserId, collect.getUserId());
        }
        if (collect.getRecipeId() != null && collect.getRecipeId() != 0 && !Objects.equals(collect.getRecipeId(), "")) {
            lambdaQueryWrapper.eq(Collect::getRecipeId, collect.getRecipeId());
        }
        
        Page<Collect> collectPage = collectMapper.selectPage(pageInfo, lambdaQueryWrapper);

        return collectPage;
    }
}




